<template>
    <div class="loading-mask" v-if="isShow" :style="maskStyle">
        <div class="loading"></div>
        <span class="m-t-10 c-555 c-primary" v-if="msg">
            {{ msg }}
        </span>
    </div>
</template>

<script>
export default {
    name: 'kl-loading',
    props:{
        msg:{
            type: String,
            default: '',
        },
        maskStyle:{
            type: Object,
            default: () => ({})
        }
    },
    data() {
        return {
            isShow: true,
        }
    },
    methods: {
        show() {
            this.isShow = true
        },
        hide() {
            this.isShow = false
        },
    },
}
</script>

<style lang="scss" scoped>
$radius: 30px;
.loading-mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    background-color: rgba(0, 0, 0, 0.15);
    z-index:2000;
}

.loading {
    width: calc($radius * 2);
    height: calc($radius * 2);
    border: 3px dotted $primary;
    border-style: solid solid dotted dotted;
    border-radius: 50%;
    display: inline-block;
    position: relative;
    box-sizing: border-box;
    animation: rotation 2s linear infinite;
}

.loading::after {
    content: '';
    box-sizing: border-box;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    border: 3px dotted $primary;
    border-style: solid solid dotted;
    width: $radius;
    height: $radius;
    border-radius: 50%;
    animation: rotationBack 1s linear infinite;
    transform-origin: center center;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes rotationBack {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(-360deg);
    }
}
</style>
